package com.metacube.questionbank.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import com.metacube.questionbank.dto.AnswerDTO;

public class AnswerExtractor implements ResultSetExtractor<AnswerDTO>{
	
	AnswerDTO aDTO = new AnswerDTO();
	
	public AnswerDTO extractData(ResultSet res) throws SQLException, DataAccessException{
		
		try {
			aDTO.setaId(res.getInt("AID"));
			aDTO.setqId(res.getInt("QID"));
			aDTO.setUserId(res.getInt("USERID"));
			aDTO.setAnsweredDate(res.getDate("ANSWEREDON"));
			aDTO.setIsAccepted(res.getInt("ISACCEPTED"));
			aDTO.setVoteLike(res.getInt("VOTELIKE"));
			aDTO.setaBody(res.getString("ABODY"));
			aDTO.setIsActive(res.getInt("ISACTIVE"));
			aDTO.setModifiedDate(res.getDate("MODIFIEDDATE"));
			aDTO.setqTitle(res.getString("TITLE"));
			aDTO.setQuestionPostedBy(res.getString("NAME"));
			
		
		} catch (SQLException e) {
			
			System.out.println("Error While Set question data to list" + e.getMessage());
		}
		return aDTO;
	}
public String extractAnswer(ResultSet res) throws SQLException, DataAccessException{
		String answer=null;
		try {
			
			answer=res.getString("abody");
		
		} catch (SQLException e) {
			
			System.out.println("Error While Set question data to list" + e.getMessage());
		}
		return answer;
	}
}	